package com.aaa.day1031demo.demo5;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年10月31日10:32
 */
public class Ticket implements Runnable{

    private int ticket=100;
    private static Object lock1=new Object();
    Lock lock=new ReentrantLock();
    @Override
    public void run() {
        try {
            lock.lock();
            while (true) {
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "卖了一张票，剩余:" + --ticket + "张票");
                } else {
                    break;

                }
            }
        }finally {
            lock.unlock();
        }
    }
}
